# -*- coding: utf-8 -*-
from liberLibs import conf, package, resource


class Library(object):
    def __init__(self, library_name=None):
        self.library_name = library_name
        self.libraries = conf.library_conf_data()
        self.data = dict()
        if self.library_name:
            self.set_library(self.library_name)

    def set_library(self, library_name):
        self.library_name = library_name
        self.data = self.libraries.get(self.library_name)

    def all_libs(self):
        libs = self.libraries.keys()
        libs = sorted(libs, key=lambda key: self.libraries[key]["order"])
        return libs

    def thumbnail(self):
        icon_path = self.data.get("thumbnail_path")
        if icon_path == "default":
            icon_path = "%s/library/%s.png" % (package.get("liberIcon"), self.library_name)
        if not icon_path:
            icon_path = resource.icon_file("image.png")
        icon_path = icon_path.replace("\\", "/")
        return icon_path

    def name(self):
        return self.library_name

    def description(self):
        return self.data.get("description")

    def create_actions(self):
        return self.data.get("create_actions")

    def show_frame_range(self):
        return self.data.get("show_frame_range")

    def apply_actions(self):
        return self.data.get("apply_actions")

    def auto_thumbnail(self):
        return self.data.get("auto_thumbnail")

    def need_check_selected(self):
        return self.data.get("need_check_selected")

    def create_ext_folder(self):
        return self.data.get("create_ext_folder")

    def support_multi_ext(self):
        return self.data.get("support_multi_ext")

if __name__ == "__main__":
    a = Library()
    print a.all_libs()
